package com.ulic.customerManApplication.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.ulic.customerManApplication.code.CodeType;
import com.ulic.customerManApplication.code.CodeTypeUtil;
import com.ulic.customerManApplication.code.CodeVO;

public class LoadConfigServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void init() throws ServletException {
		ServletConfig config = getServletConfig();
		CodeType[] types = CodeType.values();
		for(int i = 0; i < types.length; i++){
			CodeType type = types[i];
			String paramValue = config.getInitParameter(type.name());
			String[] typeArray = paramValue.split(";");
			CodeVO[] codeVOArray = new CodeVO[typeArray.length];
			for(int j = 0; j < typeArray.length; j++) {
				String typeString = typeArray[j];
				String typeValue = typeString.split(":")[0];
				String typeName = typeString.split(":")[1];
				CodeVO codeVO = new CodeVO(Integer.parseInt(typeValue), typeName);
				codeVOArray[j] = codeVO;
			}
			CodeTypeUtil.setCode(type, codeVOArray);
		}
		super.init();
	}
}
